package com.atguigu.mapreduce.writeable;

import com.atguigu.mapreduce.wordcount2.WordCountDriver;
import com.atguigu.mapreduce.wordcount2.WordCountMapper;
import com.atguigu.mapreduce.wordcount2.WordCountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * 分装自己的类
 * */
public class FlowDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // 1获取job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2设置jar包路径
        job.setJarByClass(FlowDriver.class);

        // 3关联mapper和reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);

        // 4设置map输出的kv类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        // 5设置最终输出的kv类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        // 6设置输入路径和输出路径
        FileInputFormat.setInputPaths(job,new Path("D:\\output\\flowoutput")); //将上次输出结果作为输入
        FileOutputFormat.setOutputPath(job,new Path("D:\\output\\flowoutput3"));

        // 7提交job
        boolean result = job.waitForCompletion(true);

        System.exit(result ? 0 : 1);
    }
}
